package com.fzy.designpattern.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 子弹工厂类，用来创建子弹
 */
public class BulletFactory {

    /**
     * 用于存放子弹
     */
    private static Map<String, Bullet> map = new HashMap<>();

    /**
     * 发射子弹
     */
    public static Bullet getBullet(String level) {
        Bullet b;
        if (map.get(level) == null) {
            b = new Bullet("导弹");
            map.put(level, b);
        } else {
            b = map.get(level);
        }

        return b;
    }

}
